package cn.kpt.biz.service.impl;

import cn.kpt.beans.pojo.ItripUserLinkUser;
import cn.kpt.beans.vo.userinfo.ItripSearchUserLinkUserVO;
import cn.kpt.biz.service.LinkUserService;
import cn.kpt.dao.itripuserlinkuser.ItripUserLinkUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @ClassName LinkUserServiceImpl
 * @Description TODO
 * @Author kangpengtao
 * @Date 2019/10/21 16:19
 */
@Service
public class LinkUserServiceImpl implements LinkUserService {
    @Resource
    private ItripUserLinkUserMapper itripUserLinkUserMapper;

    @Override
    public List<ItripSearchUserLinkUserVO> queryLinkUser(Long id) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", id);
        List<ItripUserLinkUser> linkUsers = itripUserLinkUserMapper.getItripUserLinkUserListByMap(params);

        // 转换
        List<ItripSearchUserLinkUserVO> vos = new ArrayList<>();
        for (ItripUserLinkUser linkUser : linkUsers) {
            ItripSearchUserLinkUserVO vo = new ItripSearchUserLinkUserVO();
            BeanUtils.copyProperties(linkUser, vo);
            vos.add(vo);
        }
        return vos;
    }

    @Override
    public void addLinkUser(ItripUserLinkUser itripUserLinkUser) throws Exception {
        itripUserLinkUserMapper.insertItripUserLinkUser(itripUserLinkUser);

    }
}
